using UnityEngine;
using System.Collections;

public class NaveA : MonoBehaviour {
	
	 /// <summary>
    /// A pontuação do jogador
    /// </summary>
    int score = 0;
	int targetScore = 500;
	
	int desloc = 10;
	
	public GameObject telaAlerta1;
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	 	var movX = transform.position.x + Input.GetAxis("Horizontal") * Time.deltaTime * desloc;
		transform.position = new Vector3 (movX, transform.position.y, transform.position.z);
		//at 80% or more of target score scrren get red with alpha 0.2;
		if(score >= targetScore * 0.8 && telaAlerta1.transform.position.x != 0){
			telaAlerta1.transform.position = new Vector3 (0, telaAlerta1.transform.position.y, telaAlerta1.transform.position.z);
			Debug.Log("ALERTAAAAAAAAAAAAAAAA");
		}
		else if(score == targetScore){
			Application.LoadLevel("YouWin");
		}
		else if(score > targetScore){
			Application.LoadLevel("YouLose");
		}
	}
	
	 void OnGUI(){
        //escreve a pontuação na tela
        GUILayout.Label(" SCORE: " + score +"\nTARGET: "+targetScore );
    }  
	
	void OnTriggerEnter(Collider collider){       
		if(collider.tag=="NaveR1"){
			Destroy(collider.gameObject);
			score += 10;
		}
		else if(collider.tag=="NaveR2"){
			Destroy(collider.gameObject);
			score += 20;
		}
		else if(collider.tag=="NaveR3"){
			Destroy(collider.gameObject);
			score += 30;
		}
		else if(collider.tag=="NaveR4"){
			Destroy(collider.gameObject);
			score += 40;
		}
    }	
}
